package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Botany;
import cn.wolfcode.crm.mapper.BotanyMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IBotanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class BotanyServiceImpl implements IBotanyService{

    @Autowired
    private BotanyMapper mapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Botany record) {
        return mapper.insert(record);
    }

    @Override
    public Botany selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Botany> selectAll() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int count = mapper.queryForCount(qo);

        if (count > 0 ){
            return new PageResult(count, mapper.queryForList(qo));
        }

        return new PageResult(count, Collections.EMPTY_LIST);
    }


    @Override
    public int updateByPrimaryKey(Botany record) {
        return mapper.updateByPrimaryKey(record);
    }
}
